package eliminate.view.info;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.Graphics;
import java.io.File;
import java.io.IOException;
import java.util.Observable;
import java.util.Observer;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import eliminate.view.single.GameTimer;

@SuppressWarnings("serial")
public class GameInfo extends JPanel implements Observer{
	
	public GameInfo(){
		try {
			font = (Font.createFont(Font.TRUETYPE_FONT, new File(fontPath)).deriveFont(40f));
			
		} catch (FontFormatException | IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		setLayout(null);
		
		
		restTimeLB = new JLabel("60");
		restTimeLB.setFont(font);
		restTimeLB.setForeground(Color.WHITE);
		restTimeLB.setHorizontalAlignment(JLabel.CENTER);
		restTimeLB.setVerticalAlignment(JLabel.CENTER);
	    add(restTimeLB);
		restTimeLB.setBounds(52, 87, 176, 47);
		
		scoreLB = new JLabel("0");
		scoreLB.setFont(font);
		scoreLB.setForeground(Color.WHITE);
		scoreLB.setHorizontalAlignment(JLabel.CENTER);
		scoreLB.setVerticalAlignment(JLabel.CENTER);
		add(scoreLB);
		scoreLB.setBounds(52, 176, 176, 45);
		
		maxComboLB = new JLabel("0");
		maxComboLB.setFont(font);
		maxComboLB.setForeground(Color.WHITE);
		maxComboLB.setHorizontalAlignment(JLabel.CENTER);
		maxComboLB.setVerticalAlignment(JLabel.CENTER);
		add(maxComboLB);
		maxComboLB.setBounds(52, 261, 176, 42);
	}
	
	@Override
	public void update(Observable arg0, Object arg1) {
		
		restTimeLB.setText(Integer.toString(((GameTimer)arg0).getRestTime()));
		scoreLB.setText(Integer.toString(((GameTimer)arg0).getScore()));
		maxComboLB.setText(Integer.toString(((GameTimer)arg0).getMaxCombo()));
		repaint();
	}
	
	@Override
	protected void paintComponent(Graphics g) {
		g.drawImage(new ImageIcon(background_pic).getImage(), 0, 0,
				278, 450, this);
	}
	
	
	private String background_pic = "media/image/gameInfo/info.jpg";
	private String fontPath = "media/font/font.ttf";
	private Font font;
	
	private JLabel restTimeLB;
	private JLabel maxComboLB;
	private JLabel scoreLB;
}
